﻿using System;
using Demo.Common.ExceptionTypes;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace Demo.Common.ExceptionHandlers
{
    public static class BusinessLogicExceptionHandler
    {
        public static bool HandleExcetion(ref Exception ex)
        {
            bool rethrow;
            if ((ex is DataAccessException) || (ex is DataAccessCustomException))
            {
                rethrow = ExceptionPolicy.HandleException(ex, "PassThroughPolicy");
                ex = new PassThroughException(ex.Message);
            }
            else if (ex is BusinessLogicCustomException)
            {
                rethrow = ExceptionPolicy.HandleException(ex, "BusinessLogicCustomPolicy");
            }
            else
            {
                rethrow = ExceptionPolicy.HandleException(ex, "BusinessLogicPolicy");
            }
            if (rethrow)
            {
                throw ex;
            }
            return false;
        }

    }
}